#include "earthdawn.h"

#include <QObject>

namespace ed
{
QString poolString(const DicePool &pool)
{
  if (pool.isEmpty()) return "";

  QString result;
  foreach(ed::Die d, ed::Die::values())
  {
    int count = pool.count(d);
    if (count>0)
    {
      result += (count > 1 ? QString::number(count) : "") + (QString)d + " + ";
    }
  }
  result.remove(result.length() - 3,3);
  return result;
}
}

namespace ed
{
QVector<__Attribute_value__> ed::Attribute::VALS = QVector<__Attribute_value__>();
QVector<QString> ed::Attribute::STR = QVector<QString>();
void Attribute::init()
{
  if (STR.isEmpty())
  {
    STR.push_back(QObject::trUtf8("Dextérité"));
    STR.push_back(QObject::trUtf8("Force"));
    STR.push_back(QObject::trUtf8("Constitution"));
    STR.push_back(QObject::trUtf8("Perception"));
    STR.push_back(QObject::trUtf8("Volonté"));
    STR.push_back(QObject::trUtf8("Charisme"));
  }
  if (VALS.isEmpty())
  {
    VALS.push_back(Attr_DEX);
    VALS.push_back(Attr_FOR);
    VALS.push_back(Attr_CON);
    VALS.push_back(Attr_PER);
    VALS.push_back(Attr_VOL);
    VALS.push_back(Attr_CHA);
  }
}
Attribute::Attribute(): _val((Value)0) { init(); }
Attribute::Attribute(int value): _val((Value)value) { init(); }
Attribute::Attribute(Value value): _val(value) { init(); }

bool Attribute::operator==(const Attribute &other) const { return _val == other._val; }
QList<Attribute> Attribute::values() { init(); QList<Attribute> result; foreach(Value v, VALS) result << v; return result; }
Attribute Attribute::fromString(const QString &str) { init(); int i= STR.indexOf(str); Q_ASSERT(i >= 0); return Attribute(VALS[i]); }
Attribute::operator __Attribute_value__() const { return _val; }
Attribute::operator QString() const { return STR[_val]; }
}

namespace ed
{
QVector<__Race_value__> ed::Race::VALS = QVector<__Race_value__>();
QVector<QString> ed::Race::STR = QVector<QString>();
void Race::init()
{
  if (STR.isEmpty())
  {
    STR.push_back(QObject::trUtf8("Humain"));
    STR.push_back(QObject::trUtf8("Ork"));
    STR.push_back(QObject::trUtf8("Nain"));
    STR.push_back(QObject::trUtf8("Elfe"));
    STR.push_back(QObject::trUtf8("Obsidien"));
    STR.push_back(QObject::trUtf8("Sylphelin"));
    STR.push_back(QObject::trUtf8("Troll"));
    STR.push_back(QObject::trUtf8("T'skrang"));
  }
  if (VALS.isEmpty())
  {
    VALS.push_back(Race_Humain);
    VALS.push_back(Race_Ork);
    VALS.push_back(Race_Nain);
    VALS.push_back(Race_Elfe);
    VALS.push_back(Race_Obsidien);
    VALS.push_back(Race_Sylphelin);
    VALS.push_back(Race_Troll);
    VALS.push_back(Race_Tskrang);
  }
}
Race::Race(): _val((Value)0) { init(); }
Race::Race(int value): _val((Value)value) { init(); }
Race::Race(Value value): _val(value) { init(); }
bool Race::operator==(const Race &other) const { return _val == other._val; }
bool Race::operator==(const Value &other) const { return _val == other; }
QList<Race> Race::values() { init(); QList<Race> result; foreach(Value v, VALS) result << v; return result; }
Race Race::fromString(const QString &str) { init(); int i= STR.indexOf(str); Q_ASSERT(i >= 0); return Race(VALS[i]); }
Race::operator Value() const { return _val; }
Race::operator QString() const { return STR[_val]; }
}

namespace ed
{
QVector<__Die_value__> ed::Die::VALS = QVector<__Die_value__>();
QVector<QString> ed::Die::STR = QVector<QString>();
void Die::init()
{
  if (STR.isEmpty())
  {
    STR.push_back(QObject::trUtf8("D4-2"));
    STR.push_back(QObject::trUtf8("D4-1"));
    STR.push_back(QObject::trUtf8("D4"));
    STR.push_back(QObject::trUtf8("D6"));
    STR.push_back(QObject::trUtf8("D8"));
    STR.push_back(QObject::trUtf8("D10"));
    STR.push_back(QObject::trUtf8("D12"));
    STR.push_back(QObject::trUtf8("D20"));
    STR.push_back(QObject::trUtf8("D100"));
  }
  if (VALS.isEmpty())
  {
    VALS.push_back(Die_D4_2);
    VALS.push_back(Die_D4_1);
    VALS.push_back(Die_D4);
    VALS.push_back(Die_D6);
    VALS.push_back(Die_D8);
    VALS.push_back(Die_D10);
    VALS.push_back(Die_D12);
    VALS.push_back(Die_D20);
    VALS.push_back(Die_D100);
  }
}
Die::Die(): _val((Value)0) { init(); }
Die::Die(int value): _val((Value)value) { init(); }
Die::Die(Value value): _val(value) { init(); }
QList<Die> Die::values() { init(); QList<Die> result; foreach(Value v, VALS) result << v; return result; }
Die Die::fromString(const QString &str) { init(); int i= STR.indexOf(str); Q_ASSERT(i >= 0); return Die(VALS[i]); }

bool Die::operator==(const Die &other) const { return _val == other._val; }
Die::operator Value() const { return _val; }
Die::operator QString() const { return STR[_val]; }
}

namespace ed
{
QVector<__Characteristic_value__> ed::Characteristic::VALS = QVector<__Characteristic_value__>();
QVector<QString> ed::Characteristic::STR = QVector<QString>();
void Characteristic::init()
{
  if (STR.isEmpty())
  {
    STR.push_back(QObject::trUtf8("Initiative"));
    STR.push_back(QObject::trUtf8("Défense physique"));
    STR.push_back(QObject::trUtf8("Défense magique"));
    STR.push_back(QObject::trUtf8("Défense sociale"));
    STR.push_back(QObject::trUtf8("Vitesse de déplacement"));
    STR.push_back(QObject::trUtf8("Vitesse de course"));
    STR.push_back(QObject::trUtf8("Capacité de transport"));
    STR.push_back(QObject::trUtf8("Capacité à soulever"));
    STR.push_back(QObject::trUtf8("Seuil de mort"));
    STR.push_back(QObject::trUtf8("Seuil d'inconscience"));
    STR.push_back(QObject::trUtf8("Seuil de blessure grave"));
    STR.push_back(QObject::trUtf8("Tests de récupération (par jour)"));
    STR.push_back(QObject::trUtf8("Armure physique"));
    STR.push_back(QObject::trUtf8("Armure mystique"));
    STR.push_back(QObject::trUtf8("Vitesse de déplacement (vol)"));
    STR.push_back(QObject::trUtf8("Vitesse de course (vol)"));
  }
  if (VALS.isEmpty())
  {
    VALS.push_back(Char_Initiative);
    VALS.push_back(Char_PhysicalDefense);
    VALS.push_back(Char_MagicDefense);
    VALS.push_back(Char_SocialDefense);
    VALS.push_back(Char_WalkSpeed);
    VALS.push_back(Char_RunSpeed);
    VALS.push_back(Char_CarryCapacity);
    VALS.push_back(Char_LiftCapacity);
    VALS.push_back(Char_Death);
    VALS.push_back(Char_Uncounciousness);
    VALS.push_back(Char_Injury);
    VALS.push_back(Char_RecuperationCount);
    VALS.push_back(Char_PhysicalArmor);
    VALS.push_back(Char_MysticalArmor);
    VALS.push_back(Char_FlightSpeed);
    VALS.push_back(Char_FlightRunSpeed);
  }
}
Characteristic::Characteristic(): _val((Value)0) { init(); }
Characteristic::Characteristic(int value): _val((Value)value) { init(); }
Characteristic::Characteristic(Value value): _val(value) { init(); }
QList<Characteristic> Characteristic::values() { init(); QList<Characteristic> result; foreach(Value v, VALS) result << v; return result; }
Characteristic Characteristic::fromString(const QString &str) { init(); int i= STR.indexOf(str); Q_ASSERT(i >= 0); return Characteristic(VALS[i]); }
Characteristic::operator Value() const { return _val; }
Characteristic::operator QString() const { return STR[_val]; }
}
